<?php
//dox1.php
//Make D-O-X types of graphs
//Written by Hongjie Qu
//Last Updated: August 2009
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title>DOX Graph Result</title>
  <link rel="stylesheet" type="text/css" href="./styles1/tabber.css">
  <script type="text/javascript" src="./js/tabber.js"></script>

  <?php
    include 'header.php';
  ?>

<?php
$username = "fossilplot";
$password = "fossilplot";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
 or die("Unable to connect to MySQL");


//select a database to work with
$selected = mysql_select_db("fossilplot",$dbhandle)
  or die("Could not select examples");

$debug=0;
//$fad=$_POST['fad'];
//$lad=$_POST['lad'];
$gen=$_POST['gen'];
//echo "gen: $gen<br>";
//$valuephy=$_POST['showphy'];
// "Phylum: $valuephy"; //for debug
$gen="(".$gen.")";
//echo "gen: $gen<br>"; //for debug
$result = mysql_query("select * from genus where id in $gen");
$resultfl=mysql_query("SELECT DISTINCT lad_date, fad_date, count(id) FROM genus where id in $gen group by lad_date, fad_date");
$resultphy=mysql_query("SELECT DISTINCT phylum_name FROM genus where id in $gen");
echo "Phylum: ";
while ($rowphy = mysql_fetch_array($resultphy)) {

	echo "<font size=1>".$rowphy{'phylum_name'}."</font>"."  ";
}
	

$File = "fossilplot.csv"; 
if (file_exists($File)){
unlink($File);
}
$Handle = fopen($File, 'w');

$Data="Genus_ID".","."Genus_Name".","."Phylum_Name".","."Class_Name".","."Order_Name".","."Fad_Period".","."Fad_Stage".","."Fad_Date".","."Lad_Period".","."Lad_Stage".","."Lad_Date"."\n";
fwrite($Handle, $Data);
while ($row = mysql_fetch_array($result)) {
//$Data=$Data.$row{'id'}.",".$row{'genus_name'}.",".$row{'phylum_name'}.",".$row{'class_name'}.",".$row{'order_name'}.",".$row{'fad_period'}.",".$row{'fad_stage'}.",".$row{'fad_date'}.",".$row{'lad_period'}.",".$row{'lad_stage'}.",".$row{'lad_date'}."\n";
$Data=$row{'id'}.",".$row{'genus_name'}.",".$row{'phylum_name'}.",".$row{'class_name'}.",".$row{'order_name'}.",".$row{'fad_period'}.",".$row{'fad_stage'}.",".$row{'fad_date'}.",".$row{'lad_period'}.",".$row{'lad_stage'}.",".$row{'lad_date'}."\n";

fwrite($Handle, $Data);
  

}
//fwrite($Handle, $Data);
fclose($Handle);

//echo "<form id=\"formcsv\" name=\"formcsv\" method=\"post\" action=\"csvdata.php\">";
echo "<br><a href=\"http://www.fossilplot.org/test/new/v9/graph/fossilplot.csv\" target=\"_blank\"><font color='red' size=1>Download CSV File of Genus Data</font></a> ";
//echo "</form>";
//$valueord=$_POST['showord'];
//echo "order: $valueord";

$d=$_POST['diversity'];
$o=$_POST['Origination'];
$e=$_POST['Extinction'];
$radio=$_POST['rd'];

$relative =$_POST['categorical'];
$absolute = $_POST['Timerange'];
$from=$_POST['from'];
$end=$_POST['end'];
$label=$_POST['label'];




//echo "from is $from<br>";
//echo "end is $end<br>";
//echo "label is $label<br>";



//$arrfad=explode(',',$fad);
//$arrlad=explode(',',$lad);

//echo "relative time is $relative<br>";
//echo "absolute time is $absolute";

//echo "fad is $fad<br><br>";
//echo "lad is $lad<br><br>";

//echo "d is $d"."<br>";
//echo "o is $o"."<br>";
//echo "e is $e"."<br>";

//echo "radio is $radio"."<br>";
//echo "radio_o is $radio_o"."<br>";
//echo "radio_e is $radio_e"."<br>";


//for ($i=0; $i<sizeof($arrfad);$i++){
 // echo $arrfad[$i]."<br>";

//}

if($relative == "Epoch"){
	$result_stgintv=mysql_query("select * from stgintv") or die ("error selecting from stgintv!!");
	for($tmp=0; $tmp<mysql_num_rows($result_stgintv); $tmp++ ){
	  $arr[$tmp]=0; 
	  $arrdvt[$tmp] =0;
	  $arrext[$tmp]=0;
	 }
	 
	 //for ($i=0; $i<sizeof($arrfad);$i++){
	 while ($rowfl = mysql_fetch_array($resultfl)) {

		while($row_stgintv=mysql_fetch_array($result_stgintv)){
		  if ($row_stgintv{'end'}<$rowfl{'fad_date'} && $rowfl{'fad_date'}<= $row_stgintv{'begin'}){ //this if for origination
			  $arr[$row_stgintv{'id'}]+=$rowfl{'count(id)'};
			 // break;
		  }
	      
		  if($row_stgintv{'end'}>0){
			if($rowfl{'lad_date'} < $row_stgintv{'begin'} && $rowfl{'lad_date'} >= $row_stgintv{'end'}){
				$arrext[$row_stgintv{'id'}] += $rowfl{'count(id)'};
      
			}
		  }else{
			if($rowfl{'lad_date'} < $row_stgintv{'begin'} && $rowfl{'lad_date'} > $row_stgintv{'end'}){
				$arrext[$row_stgintv{'id'}] += $rowfl{'count(id)'};
      
			}
		  
		  }
	      
		  if($rowfl{'fad_date'} <= $row_stgintv{'begin'} && $rowfl{'lad_date'} >= $row_stgintv{'end'}){
			$arrdvt[$row_stgintv{'id'}] += $rowfl{'count(id)'};
			//break;
		  }
		  else if($rowfl{'fad_date'} < $row_stgintv{'begin'} && $rowfl{'fad_date'} > $row_stgintv{'end'}){
			$arrdvt[$row_stgintv{'id'}] += $rowfl{'count(id)'};
			//break;
		  }
		  else if($rowfl{'lad_date'} < $row_stgintv{'begin'} && $rowfl{'lad_date'} > $row_stgintv{'end'}){
			$arrdvt[$row_stgintv{'id'}] += $rowfl{'count(id)'};
      
			//break;
		  }
		  else if($rowfl{'fad_date'} >= $row_stgintv{'begin'} && $rowfl{'lad_date'} <= $row_stgintv{'end'}){
			$arrdvt[$row_stgintv{'id'}] += $rowfl{'count(id)'};
			//break;
		  }
	      
	      
	  
	  
		} 
		$result_stgintv=mysql_query("select * from stgintv") or die ("error!!"); 
	 }
 } // end of if radio=count3 || relative==epoch
 
 
 else if($relative=="Period"){
 
 
 
	 $result_period=mysql_query("select * from period") or die ("error selecting from stgintv!!");
		for($tmp=0; $tmp<mysql_num_rows($result_period); $tmp++ ){
		  $arr[$tmp]=0; 
		  $arrdvt[$tmp] =0;
		  $arrext[$tmp]=0;
		 }
		 
		 //for ($i=0; $i<sizeof($arrfad);$i++){
		 while ($rowfl = mysql_fetch_array($resultfl)) {
			while($row_period=mysql_fetch_array($result_period)){
			  if ($row_period{'end'}<$rowfl{'fad_date'} && $rowfl{'fad_date'}<= $row_period{'begin'}){ //this if for origination
				  $arr[$row_period{'id'}]+=$rowfl{'count(id)'};
				 // break;
				 //echo "id is ".$row_period{'id'}."<br>";
			  }
		      
			  if($row_period{'end'}>0){
				if($rowfl{'lad_date'} < $row_period{'begin'} && $rowfl{'lad_date'} >= $row_period{'end'}){
					$arrext[$row_period{'id'}] += $rowfl{'count(id)'};
					//echo "id is ".$row_period{'id'}."<br>";
				}
			  }else{
				if($rowfl{'lad_date'} < $row_period{'begin'} && $rowfl{'lad_date'} > $row_period{'end'}){
					$arrext[$row_period{'id'}] += $rowfl{'count(id)'};
					//echo "id is ".$row_period{'id'}."<br>";
				}
			  
			  }
		      
			  if($rowfl{'fad_date'} <= $row_period{'begin'} && $rowfl{'lad_date'} >= $row_period{'end'}){
				$arrdvt[$row_period{'id'}] += $rowfl{'count(id)'};
				//break;
				//echo "id is ".$row_period{'id'}."<br>";
			  }
			  else if($rowfl{'fad_date'} < $row_period{'begin'} && $rowfl{'fad_date'} > $row_period{'end'}){
				$arrdvt[$row_period{'id'}] += $rowfl{'count(id)'};
				//break;
				//echo "id is ".$row_period{'id'}."<br>";
			  }
			  else if($rowfl{'lad_date'} < $row_period{'begin'} && $rowfl{'fad_date'} > $row_period{'end'}){
				$arrdvt[$row_period{'id'}] += $rowfl{'count(id)'};
				//break;
				//echo "id is ".$row_period{'id'}."<br>";
			  }
			  else if($rowfl{'fad_date'} >= $row_period{'begin'} && $rowfl{'lad_date'} <= $row_period{'end'}){
				$arrdvt[$row_period{'id'}] += $rowfl{'count(id)'};
				//break;
				//echo "id is ".$row_period{'id'}."<br>";
			  }		  
			} 
			$result_period=mysql_query("select * from period") or die ("error!!"); 
		 } 
		 
		 //echo "size of arr is ".sizeof($arr)."<br>";
 } 
 
 else if($relative=="Stage"){
 
	$result_stage=mysql_query("select * from stage") or die ("error selecting from stgintv!!");
		for($tmp=0; $tmp<mysql_num_rows($result_stage); $tmp++ ){
		  $arr[$tmp]=0; 
		  $arrdvt[$tmp] =0;
		  $arrext[$tmp]=0;
		 }
		 
		 //for ($i=0; $i<sizeof($arrfad);$i++){
		 while ($rowfl = mysql_fetch_array($resultfl)) {
			while($row_stage=mysql_fetch_array($result_stage)){
			  if ($row_stage{'end'}<$rowfl{'fad_date'} && $rowfl{'fad_date'}<= $row_stage{'begin'}){ //this if for origination
				  $arr[$row_stage{'id'}]+=$rowfl{'count(id)'};
				 // break;
			  }
		      
			  if($row_stage{'end'}>0){
				if($rowfl{'lad_date'} < $row_stage{'begin'} && $rowfl{'lad_date'} >= $row_stage{'end'}){
					$arrext[$row_stage{'id'}] += $rowfl{'count(id)'};
				}
			  }else{
				if($rowfl{'lad_date'} < $row_stage{'begin'} && $rowfl{'lad_date'} > $row_stage{'end'}){
					$arrext[$row_stage{'id'}] += $rowfl{'count(id)'};
				}
			  
			  }
		      
			  if($rowfl{'fad_date'} <= $row_stage{'begin'} && $rowfl{'lad_date'} >= $row_stage{'end'}){
				$arrdvt[$row_stage{'id'}] += $rowfl{'count(id)'};
				//break;
			  }
			  else if($rowfl{'fad_date'} < $row_stage{'begin'} && $rowfl{'fad_date'} > $row_stage{'end'}){
				$arrdvt[$row_stage{'id'}] += $rowfl{'count(id)'};
				//break;
			  }
			  else if($rowfl{'lad_date'} < $row_stage{'begin'} && $rowfl{'lad_date'} > $row_stage{'end'}){
				$arrdvt[$row_stage{'id'}] += $rowfl{'count(id)'};
				//break;
			  }
			  else if($rowfl{'fad_date'} >= $row_stage{'begin'} && $rowfl{'lad_date'} <= $row_stage{'end'}){
				$arrdvt[$row_stage{'id'}] += $rowfl{'count(id)'};
				//break;
			  }
			} 
			$result_stage=mysql_query("select * from stage") or die ("error!!"); 
		 } 
 }
 
 else if($relative=="none" || $radio=="Rate3"){
	$key=1;
	//for($i=5;$i<51;$i++){
		//if($absolute ==$i) 
			//{$key=1; break;} 
	//}
	
	if($from=="" || $end==""|| $absolute==""){
		$key=0;
	}
	if($from<0 ||$from>570||$end<0||$end>570||$absoluet<0){
		$key=0;
	}
	
	$abs=abs($from -$end);
	if($abs==0 || ($abs/$absolute)<10 ||($abs/$absolute)>150){
		$key=0;
	}
	
	if($key==1){
		if(is_int($abs/$absolute)){
			$xaxis_num=$abs/$absolute;
		}
		else{
			$xaxis_num=ceil($abs/$absolute);
		}
		
	if($from < $end){
	$tmp=$from;
	$from=$end;
	$end=$tmp;
		
	}
		//echo "xaxis_num is $xaxis_num<br>";
		for($tmp=0; $tmp<$xaxis_num; $tmp++ ){
		  $arr[$tmp]=0; 
		  $arrdvt[$tmp] =0;
		  $arrext[$tmp]=0;
		}
		
		//for ($i=0; $i<sizeof($arrfad);$i++){
		while ($rowfl = mysql_fetch_array($resultfl)) {
			for($j=$xaxis_num-1;$j>=0;$j--){			
			
				if (($absolute*$j+$end)<=$rowfl{'fad_date'} && $rowfl{'fad_date'}<= ($absolute*($j+1)-0.001+$end)){ //this if for origination
					  $arr[$xaxis_num-$j-1]+=$rowfl{'count(id)'};
					  //echo "j is $j<br>";
					 // break;
				  }
			      
				  if(($absolute*$j+$end)>0){
					if($rowfl{'lad_date'} <= ($absolute*($j+1)-0.001+$end) && $rowfl{'lad_date'} >= ($absolute*$j+$end)){
						$arrext[$xaxis_num-$j-1] += $rowfl{'count(id)'};
					}
				  }else{
					if($rowfl{'lad_date'} <= ($absolute*($j+1)-0.001+$end) && $rowfl{'lad_date'} > ($absolute*$j+$end)){
						$arrext[$xaxis_num-$j-1] += $rowfl{'count(id)'};
					}
				  
				  }
			      
				  if($rowfl{'fad_date'} <= ($absolute*($j+1)-0.001+$end) && $rowfl{'lad_date'} >= ($absolute*$j+$end)){
					$arrdvt[$xaxis_num-$j-1] += $rowfl{'count(id)'};
					//break;
				  }
				  else if($rowfl{'fad_date'} < ($absolute*($j+1)-0.001+$end) && $rowfl{'fad_date'} > ($absolute*$j+$end)){
					$arrdvt[$xaxis_num-$j-1] += $rowfl{'count(id)'};
					//break;
				  }
				  else if($rowfl{'lad_date'} < ($absolute*($j+1)-0.001+$end) && $rowfl{'lad_date'} > ($absolute*$j+$end)){
					$arrdvt[$xaxis_num-$j-1] += $rowfl{'count(id)'};
					//break;
				  }
				  else if($rowfl{'fad_date'} >= ($absolute*($j+1)-0.001+$end) && $rowfl{'lad_date'} <= ($absolute*$j+$end)){
					$arrdvt[$xaxis_num-$j-1] += $rowfl{'count(id)'};
					//break;
				  }			
			}			
		}
	
	}//end of if(key==1)
}
 
 
 //for($tmp=sizeof($arr); $tmp>=0; $tmp-- ){
  //print "arr $tmp is ".$arr[$tmp]."<br>";
 //}
 
 if($debug){
 $total=0;
 for($tmp=0; $tmp<sizeof($arrext); $tmp++ ){
  print "arrext is ".$arrext[$tmp]."<br>";
   $total = $total+ $arrext[$tmp];
 }
 echo "total is ".$total;
 
 } //debug
 
 
 
 
 
 
 if($relative && $relative != "none"){
if($relative=="Period") $resultintv = mysql_query("select * from period");
if($relative=="Epoch")  $resultintv = mysql_query("select * from stgintv");
if($relative=="Stage")  $resultintv = mysql_query("select * from stage");


$File = "interval.csv"; 
if (file_exists($File)){
unlink($File);
}
$Handle = fopen($File, 'w');
if($d=="on"){
	if($o=="on"){
		if($e=="on"){
			$Data="Interval Name".","."Begin".","."End".","."Div. Y-Value".","."Orig. Y-Value".","."Ext. Y-Value"."\n";

		}//e is on
		else{ //d, o on, e off
			$Data="Interval Name".","."Begin".","."End".","."Div. Y-Value".","."Orig. Y-Value"."\n";
		}
	
	}//o is on
	else{//o is off, e may on or off
		if($e=="on"){
			$Data="Interval Name".","."Begin".","."End".","."Div. Y-Value".","."Ext. Y-Value"."\n";
		}
		else{//o and e off
			$Data="Interval Name".","."Begin".","."End".","."Div. Y-Value"."\n";
		}
	
	}

}
else{//d off
	if($o=="on"){
		if($e=="on"){
			$Data="Interval Name".","."Begin".","."End".","."Orig. Y-Value".","."Ext. Y-Value"."\n";
		
		}
		else{
			$Data="Interval Name".","."Begin".","."End".","."Orig. Y-Value"."\n";
		
		}
	
	
	}//o on
	else{
		if($e=="on"){
			$Data="Interval Name".","."Begin".","."End".","."Ext. Y-Value"."\n";
		}
	}


}
//$Data="Interval Name".","."Begin".","."End"."\n";
fwrite($Handle, $Data);

while ($rowintv = mysql_fetch_array($resultintv)) {
if($relative=="Period")  $name='pd_short';//$Data=$rowintv{'pd_short'}.",".$rowintv{'begin'}.",".$rowintv{'end'}."\n";
if($relative=="Epoch")  $name='stage_interval';//$Data=$rowintv{'stage_interval'}.",".$rowintv{'begin'}.",".$rowintv{'end'}."\n";
if($relative=="Stage")  $name='stage';//$Data=$rowintv{'stage'}.",".$rowintv{'begin'}.",".$rowintv{'end'}."\n";
//$Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}."\n";
$id=$rowintv{'id'};
if($d=="on"){
	if($o=="on"){
		if($e=="on"){
			$Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}.",".$arrdvt[$id].",".$arr[$id].",".$arrext[$id]."\n";		
		}
		else{//d,o on, e off
			$Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}.",".$arrdvt[$id].",".$arr[$id]."\n";		
		}
	
	}
	else{ // o off, e on or off
		if($e=="on"){
			$Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}.",".$arrdvt[$id].",".$arrext[$id]."\n";
		}
		else{
			$Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}.",".$arrdvt[$id]."\n";
		
		}
	}
}
else{//d off, o,e on or off
	if($o=="on"){
		if($e=="on"){
			$Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}.",".$arr[$id].",".$arrext[$id]."\n";
		}
		else{
			$Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}.",".$arr[$id]."\n";
		}
	}
	else{
		if($e=="on") $Data=$rowintv{$name}.",".$rowintv{'begin'}.",".$rowintv{'end'}.",".$arrext[$id]."\n";
	}

}

fwrite($Handle, $Data);
  

}
fclose($Handle);

echo "<br><br><a href=\"http://www.fossilplot.org/test/new/v9/graph/interval.csv\" target=\"_blank\"><font color='red' size=1>Download CSV File of Graph Data</font></a> ";
} 




 
 
 if($o=="on"){ 
  //$File = "../../../admin1/list/graph/write.php";
  
  $File = "../../../graph/write.php"; 
  $Handle = fopen($File, 'w');
  if($radio=="Rate3"){
    $Data = "<?php
    include (\"./src/jpgraph.php\");
    include (\"./src/jpgraph_line.php\");
    \$datay=array";
    fwrite($Handle, $Data);
	
	$total=0;
	for($tmp=1; $tmp<sizeof($arr); $tmp++){
      $total += $arr[$tmp];
	}
	//$first=$arr[0]/sizeof($arrfad)*100;
	$first=$arr[0]/$total*100;
    $barval="($first";
    for($tmp=1; $tmp<sizeof($arr); $tmp++){
      //$rate=($arr[$tmp]/sizeof($arrfad))*100;
	  $rate=($arr[$tmp]/$total)*100;
      $barval =$barval.",".$rate;
    }
    $barval=$barval.")";
	$rateo=$barval;
    if($debug) {echo "barvalue is".$barval;}
    $Data="$barval;
    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");
    \$graph->SetShadow();";
	fwrite($Handle, $Data);		
	if($key==1){	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
	if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  
  
  $Data="
	\$graph->xaxis->SetTickLabels(\$datax);
  
  //\$graph->xaxis->SetTextTickInterval(3);
    \$graph->xaxis->SetLabelAngle(90);
    \$graph->img->SetMargin(40,30,20,120);
    \$lineplot = new LinePlot(\$datay);  
    
    ";
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot->mark->SetType(MARK_UTRIANGLE);
      \$lineplot->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
     
    \$graph->Add(\$lineplot);
    \$graph->title->Set(\"Rate of Origination\");
    \$graph->xaxis->title->Set(\"Absolute Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Rate of Genera\");
    
    \$lineplot->SetColor(\"green\");
    \$lineplot->SetWeight(2);
    \$lineplot->value->SetColor(\"green\"); 
    
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";

    
  } // end of if radio_o=Rate3
  else{
    $Data = "<?php
    include (\"./src/jpgraph.php\");
    include (\"./src/jpgraph_bar.php\");
    \$datay=array";
    fwrite($Handle, $Data);
    $barval="($arr[0]";
    for($tmp=1; $tmp<sizeof($arr); $tmp++){    
      $barval =$barval.",".$arr[$tmp];
    }
    $barval=$barval.")";
    if($debug) {echo "barvalue is".$barval;}
    $Data="$barval;

    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");    
    \$graph->SetShadow();";
	fwrite($Handle, $Data);	
	if($relative=="Period"){
		$Data="
		    \$datax = array(\"Cv\",\"O\",\"S\",\"D\",\"C\",\"P\",\"Tr\",\"J\",\"K\",\"Pg\",\"Ng\");
			";
		fwrite($Handle, $Data);

	}
	else if($relative=="Epoch"){
		$Data="
		\$datax = array(\"V\",\"Cm(l)\",\"Cm(m)\",\"Cm(u)\",\"O(l)\",\"O(m)\",\"O(u)\",\"S(l)\",\"S(m)\",\"S(u)\",\"D(l)\",\"D(m)\",\"D(u)\",\"CMs\",\"CPn\",\"P(l)\",\"P(u)\",\"Tr(l)\",\"Tr(m)\",\"Tr(u)\",\"J(l)\",\"J(m)\",\"J(u)\",\"K(l)\",\"K(u)\",\"Pg(Pal)\",\"Pg(Eo)\",\"Pg(Oli)\",\"Ng(Mio)\",\"Ng(Pli)\",\"Ng(Plei)\",\"Ng(Re)\");
		";
		fwrite($Handle, $Data);
	}	
	else if($relative == "Stage"){
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		$result_stage=mysql_query("select stage from stage where id='0'") or die ("error selecting from stgintv!!");
		$stg="(";
		while($row_stage=mysql_fetch_array($result_stage)){
		
		$stg=$stg."\"".$row_stage{'stage'}."\"";
		}
		
		$result_stage=mysql_query("select stage from stage where id>'0'") or die ("error selecting from stgintv!!");

		while($row_stage=mysql_fetch_array($result_stage)){
		
			$stg=$stg.","."\"".$row_stage{'stage'}."\"";
		}
		$stg=$stg.")";
		$Data="$stg;";
		fwrite($Handle, $Data);	
	}
	
	else if($relative=="none" && $key==1){	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
    $range=$absolute*$xaxis_num+$end;
		//for($i= 2;$i<=$xaxis_num;$i++){
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
	
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  
  $Data="    
    \$graph->xaxis->SetTickLabels(\$datax);    
    \$graph->xaxis->SetLabelAngle(90);

    \$graph->img->SetMargin(40,30,20,120);
    \$bplot = new BarPlot(\$datay);
    \$bplot->SetFillColor('green');
    \$bplot->SetWidth(0.5);";
    
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$bplot->value->Show();
      ";
      fwrite($Handle, $Data);
	  
	  if($radio !="Rate3"){
		$Data="
		\$bplot->value->SetFormat('%d');
		";
		fwrite($Handle, $Data);
	  
	  }
	  
	  
     }
     $Data="
    
    
    //\$bplot->value->Show();
    \$graph->Add(\$bplot);
    \$graph->title->Set(\"Origination\");
	";
	fwrite($Handle, $Data);
	if($relative=="Period"){
		$Data="
		\$graph->xaxis->title->Set(\"Period Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	
	if($relative=="Stage"){
		$Data="
		\$graph->xaxis->title->Set(\"Stage Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	if($relative=="Epoch"){
		$Data="
		\$graph->xaxis->title->Set(\"Epoch Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	if($relative=="none"){
		$Data="
		\$graph->xaxis->title->Set(\"Absolute Time Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	$Data="
    //\$graph->xaxis->title->Set(\"Stage Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Number of Genera\");
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
  }
  fwrite($Handle, $Data);
  fclose($Handle);
  //unlink the old graph
  //$myFile = "../../../admin1/list/graph/jpgraph_cache/write.png";

  $myFile = "../../../graph/jpgraph_cache/write.png";
  if(file_exists($myFile)){
  unlink($myFile);
  }
  } //end of if($o is on)


  if($d=="on"){
  //$File = "../../../admin1/list/graph/writedvt.php";

  $File = "../../../graph/writedvt.php";
  $Handle = fopen($File, 'w');
  if($radio =="Rate3"){
  $Data = "<?php
  include (\"./src/jpgraph.php\");
  include (\"./src/jpgraph_line.php\");
  \$datay=array";
  fwrite($Handle, $Data);
    //echo "arrdvt0 is ".$arrdvt[0]."<br>";
	//echo "arrdvt1 is ".$arrdvt[1]."<br>";
  $total=0;
  for($tmp=1; $tmp<sizeof($arrdvt); $tmp++){
      $total += $arrdvt[$tmp];
  }  
  
  //echo "total is $total";
  //$first=($arrdvt[0]/$total)*100;
  $barval="($arrdvt[0]/$total*100";//Jessica July 10
  for($tmp=1; $tmp<sizeof($arrdvt); $tmp++){
    $rate=($arrdvt[$tmp]/$total)*100;
    $barval =$barval.",".$rate;
  }
  $barval=$barval.")";
	$rated=$barval;
  if($debug) {echo "barvalue is".$barval;}
  $Data="$barval;
  \$graph = new Graph(800,450,\"auto\");    
  \$graph->SetScale(\"textlin\");
  \$graph->SetShadow();";
  fwrite($Handle, $Data);  	
	if($key==1){	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
	
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  
  $Data="
  \$graph->xaxis->SetTickLabels(\$datax); 
  
  \$graph->xaxis->SetLabelAngle(90);

  \$graph->img->SetMargin(40,30,20,120);
  \$lineplot = new LinePlot(\$datay);
  ";
  
  fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot->mark->SetType(MARK_UTRIANGLE);
      \$lineplot->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
  
  
  //\$lineplot->value->Show();
  \$graph->Add(\$lineplot);
  \$graph->title->Set(\"Rate of Diversity\");
  \$graph->xaxis->title->Set(\"Absolute Time Interval\");
  \$graph->xaxis->title->SetMargin(80);
  \$graph->yaxis->title->Set(\"Rate of Genera\");
  
  \$lineplot->SetColor(\"blue\");
  \$lineplot->SetWeight(2);
  \$lineplot->value->SetColor(\"blue\");
  \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
  \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
  \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
  \$graph->Stroke();
  ?>";
  }//end of if(radio_d==on)
  else{
    $Data = "<?php
    include (\"./src/jpgraph.php\");
    include (\"./src/jpgraph_bar.php\");
    \$datay=array";
    fwrite($Handle, $Data);

    $barval="($arrdvt[0]"; 
 
    for($tmp=1; $tmp<sizeof($arrdvt); $tmp++){      
      $barval =$barval.",".$arrdvt[$tmp];
    }
    $barval=$barval.")";
    if($debug) {echo "barvalue is".$barval;}
    $Data="$barval;
    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");
  \$graph->SetShadow();";
	fwrite($Handle, $Data);	
	if($relative=="Period"){
		$Data="
		    \$datax = array(\"Cv\",\"O\",\"S\",\"D\",\"C\",\"P\",\"Tr\",\"J\",\"K\",\"Pg\",\"Ng\");
			";
		fwrite($Handle, $Data);

	}
	else if($relative=="Epoch"){
		$Data="
		\$datax = array(\"V\",\"Cm(l)\",\"Cm(m)\",\"Cm(u)\",\"O(l)\",\"O(m)\",\"O(u)\",\"S(l)\",\"S(m)\",\"S(u)\",\"D(l)\",\"D(m)\",\"D(u)\",\"CMs\",\"CPn\",\"P(l)\",\"P(u)\",\"Tr(l)\",\"Tr(m)\",\"Tr(u)\",\"J(l)\",\"J(m)\",\"J(u)\",\"K(l)\",\"K(u)\",\"Pg(Pal)\",\"Pg(Eo)\",\"Pg(Oli)\",\"Ng(Mio)\",\"Ng(Pli)\",\"Ng(Plei)\",\"Ng(Re)\");
		";
		fwrite($Handle, $Data);
	}	
	else if($relative == "Stage"){
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		$result_stage=mysql_query("select stage from stage where id='0'") or die ("error selecting from stgintv!!");
		$stg="(";
		while($row_stage=mysql_fetch_array($result_stage)){
		
		$stg=$stg."\"".$row_stage{'stage'}."\"";
		}
		
		$result_stage=mysql_query("select stage from stage where id>'0'") or die ("error selecting from stgintv!!");

		while($row_stage=mysql_fetch_array($result_stage)){
		
			$stg=$stg.","."\"".$row_stage{'stage'}."\"";
		}

		$stg=$stg.")";
		$Data="$stg;";
		fwrite($Handle, $Data);	
	}	
	else if($relative=="none" && $key==1){	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
	//fwrite($Handle, $Data);
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  //$Data="
  
  $Data="
    \$graph->xaxis->SetTickLabels(\$datax);
    \$graph->xaxis->SetLabelAngle(90);

    \$graph->img->SetMargin(40,30,20,120);
    \$bplot = new BarPlot(\$datay);
    \$bplot->SetFillColor('blue');
    \$bplot->SetWidth(0.5);";
    
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$bplot->value->Show();
      ";
      fwrite($Handle, $Data);
	  
	  if($radio !="Rate3"){
		$Data="
		\$bplot->value->SetFormat('%d');
		";
		fwrite($Handle, $Data);
	  
	  }
	  
     }
     $Data="
    
    //\$bplot->value->Show();
    \$graph->Add(\$bplot);
    \$graph->title->Set(\"Generic Diversity\");";
	
	fwrite($Handle, $Data);
	if($relative=="Period"){
		$Data="
		\$graph->xaxis->title->Set(\"Period Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	
	if($relative=="Stage"){
		$Data="
		\$graph->xaxis->title->Set(\"Stage Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	if($relative=="Epoch"){
		$Data="
		\$graph->xaxis->title->Set(\"Epoch Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	if($relative=="none"){
		$Data="
		\$graph->xaxis->title->Set(\"Absolute Time Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	$Data="
	
	
	
	
	
	
    //\$graph->xaxis->title->Set(\"Stage Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Number of Genera\");
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
    }
    fwrite($Handle, $Data);
    fclose($Handle);
    //unlink the old graph
    //$myFile = "../../../admin1/list/graph/jpgraph_cache/writedvt.png";

    $myFile = "../../../graph/jpgraph_cache/writedvt.png";
	if(file_exists($myFile)){
    unlink($myFile);
	}
    } //end of if($d is on)


    if($e=="on"){
    //$File = "../../../admin1/list/graph/writeext.php";
    $File = "../../../graph/writeext.php";
    $Handle = fopen($File, 'w');
    if($radio =="Rate3"){
    $Data = "<?php
      include (\"./src/jpgraph.php\");
      include (\"./src/jpgraph_line.php\");
      \$datay=array";
      fwrite($Handle, $Data);

      
      $total=0;
      for($tmp=1; $tmp<sizeof($arrext); $tmp++){
          $total += $arrext[$tmp];  
		  
      }
	  
	  //echo "total is $total";
	  $barval="($arrext[0]/$total*100";
      for($tmp=1; $tmp<sizeof($arrext); $tmp++){
        $rate=($arrext[$tmp]/$total)*100;
        $barval =$barval.",".$rate;
      } 
    $barval=$barval.")";
	$ratee=$barval;
    if($debug) {echo "barvalue is".$barval;}
    $Data="$barval;
    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");	
	\$graph->SetShadow();";
	fwrite($Handle, $Data);	
	if($key==1){	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}	
  
  
  //fwrite($Handle, $Data);
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  //$Data="
  
  
	$Data="
    \$graph->xaxis->SetTickLabels(\$datax);
    \$graph->xaxis->SetLabelAngle(90);
    \$graph->img->SetMargin(40,30,20,120);
    \$lineplot = new LinePlot(\$datay);
    ";
    
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot->mark->SetType(MARK_UTRIANGLE);
      \$lineplot->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
    
    //\$lineplot->value->Show();
    \$graph->Add(\$lineplot);
    \$graph->title->Set(\"Rate of Extinction\");
    \$graph->xaxis->title->Set(\"Absolute Time Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Rate of Genera\");
    \$lineplot->SetColor(\"orange\");
    \$lineplot->SetWeight(2);
    \$lineplot->value->SetColor(\"orange\");
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
   }
   else{
    $Data = "<?php
    include (\"./src/jpgraph.php\");
    include (\"./src/jpgraph_bar.php\");
    \$datay=array";
    fwrite($Handle, $Data);
    $barval="($arrext[0]"; 
    for($tmp=1; $tmp<sizeof($arrext); $tmp++){      
      $barval =$barval.",".$arrext[$tmp];
    }
    $barval=$barval.")";
    if($debug==2) {echo "barvalue is".$barval;}
    $Data="$barval;
    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");

  \$graph->SetShadow();";
	fwrite($Handle, $Data);	
	if($relative=="Period"){
		$Data="
		    \$datax = array(\"Cv\",\"O\",\"S\",\"D\",\"C\",\"P\",\"Tr\",\"J\",\"K\",\"Pg\",\"Ng\");
			";
		fwrite($Handle, $Data);

	}
	else if($relative=="Epoch"){
		$Data="
		\$datax = array(\"V\",\"Cm(l)\",\"Cm(m)\",\"Cm(u)\",\"O(l)\",\"O(m)\",\"O(u)\",\"S(l)\",\"S(m)\",\"S(u)\",\"D(l)\",\"D(m)\",\"D(u)\",\"CMs\",\"CPn\",\"P(l)\",\"P(u)\",\"Tr(l)\",\"Tr(m)\",\"Tr(u)\",\"J(l)\",\"J(m)\",\"J(u)\",\"K(l)\",\"K(u)\",\"Pg(Pal)\",\"Pg(Eo)\",\"Pg(Oli)\",\"Ng(Mio)\",\"Ng(Pli)\",\"Ng(Plei)\",\"Ng(Re)\");
		";
		fwrite($Handle, $Data);
	}
	
	else if($relative == "Stage"){
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		$result_stage=mysql_query("select stage from stage where id='0'") or die ("error selecting from stgintv!!");
		$stg="(";
		while($row_stage=mysql_fetch_array($result_stage)){
		
		$stg=$stg."\"".$row_stage{'stage'}."\"";
		}
		
		$result_stage=mysql_query("select stage from stage where id>'0'") or die ("error selecting from stgintv!!");

		while($row_stage=mysql_fetch_array($result_stage)){
		
			$stg=$stg.","."\"".$row_stage{'stage'}."\"";
		}

		$stg=$stg.")";
		$Data="$stg;";
		fwrite($Handle, $Data);	
	}	
	else if($relative=="none" && $key==1){	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
  //fwrite($Handle, $Data);
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  //$Data="
  
  
	$Data="
    \$graph->xaxis->SetTickLabels(\$datax);
    \$graph->xaxis->SetLabelAngle(90);

    \$graph->img->SetMargin(40,30,20,120);
    \$bplot = new BarPlot(\$datay);
    \$bplot->SetFillColor('orange');
    \$bplot->SetWidth(0.5);";
    
    
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$bplot->value->Show();
      ";
      fwrite($Handle, $Data);
	  
	  
	  if($radio !="Rate3"){
		$Data="
		\$bplot->value->SetFormat('%d');
		";
		fwrite($Handle, $Data);
	  
	  }
	  
	  
     }
     $Data="
    
    //\$bplot->value->Show();
    \$graph->Add(\$bplot);
    \$graph->title->Set(\"Extinction\");";
	
	
	
	fwrite($Handle, $Data);
	if($relative=="Period"){
		$Data="
		\$graph->xaxis->title->Set(\"Period Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	
	if($relative=="Stage"){
		$Data="
		\$graph->xaxis->title->Set(\"Stage Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	if($relative=="Epoch"){
		$Data="
		\$graph->xaxis->title->Set(\"Epoch Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	if($relative=="none"){
		$Data="
		\$graph->xaxis->title->Set(\"Absolute Time Interval\");
		";
		fwrite($Handle, $Data);
		
	}
	
	$Data="
	
	
	
   // \$graph->xaxis->title->Set(\"Stage Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Number of Genera\");
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
    }
    fwrite($Handle, $Data);
    fclose($Handle);
    //unlink the old graph
    //$myFile = "../../../admin1/list/graph/jpgraph_cache/writeext.png";

    $myFile = "../../../graph/jpgraph_cache/writeext.png";
	if(file_exists($myFile)){
    unlink($myFile);
	}
    } //end of if($e is on)


    if($radio=="Rate3" && ($d=="on" && $o=="on" && $e=="on")){

    //$File = "../../../admin1/list/graph/comb_dox.php";

    $File = "../../../graph/comb_dox.php";
    $Handle = fopen($File, 'w');
    $Data = "<?php
      include (\"./src/jpgraph.php\");
      include (\"./src/jpgraph_line.php\");
	  \$datay=array$rated;
	  \$datay2=array$rateo;
	  \$datay3=array$ratee;

    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");
    \$graph->SetShadow();";
	fwrite($Handle, $Data);	
	
//if($key==1){
	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	//}	
	
	
  //fwrite($Handle, $Data);
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
 // $Data="
  
  $Data="

    \$graph->xaxis->SetTickLabels(\$datax);
    \$graph->xaxis->SetLabelAngle(90);

    \$graph->img->SetMargin(40,30,20,120);
    \$lineplot = new LinePlot(\$datay);
	\$lineplot2 = new LinePlot(\$datay2);
	\$lineplot3 = new LinePlot(\$datay3);

    ";
    
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot->mark->SetType(MARK_UTRIANGLE);
      \$lineplot->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
    
    //\$lineplot->value->Show();
	
	";
  
  fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot2->mark->SetType(MARK_UTRIANGLE);
      \$lineplot2->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
  
    //\$lineplot2->value->Show();
	
	";
  
  fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot3->mark->SetType(MARK_UTRIANGLE);
      \$lineplot3->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
  
  
    //\$lineplot3->value->Show();
	
	
    \$graph->Add(\$lineplot);
	\$graph->Add(\$lineplot2);
	\$graph->Add(\$lineplot3);
    \$graph->title->Set(\"Rate of DOX\");
    \$graph->xaxis->title->Set(\"Absolute Time Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Rate of Genera\");
    \$lineplot->SetColor(\"blue\");
    \$lineplot->SetWeight(2);
    \$lineplot->value->SetColor(\"blue\");
	
	\$lineplot2->SetColor(\"green\");
    \$lineplot2->SetWeight(2);
    \$lineplot2->value->SetColor(\"green\");
	
	\$lineplot3->SetColor(\"orange\");
    \$lineplot3->SetWeight(2);
    \$lineplot3->value->SetColor(\"orange\");
	
	
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
    fwrite($Handle, $Data);
    fclose($Handle);
    //$myFile = "../../../admin1/list/graph/jpgraph_cache/comb_dox.png";

    $myFile = "../../../graph/jpgraph_cache/comb_dox.png";
	if(file_exists($myFile)){
    unlink($myFile);
	}

    }

    else if($radio=="Rate3" && $d=="on" && $o=="on"){

    //$File = "../../../admin1/list/graph/comb_dox.php";

    $File = "../../../graph/comb_dox.php";
    $Handle = fopen($File, 'w');
    $Data = "<?php
      include (\"./src/jpgraph.php\");
      include (\"./src/jpgraph_line.php\");
	  \$datay=array$rated;
	  \$datay2=array$rateo;
	  

    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");
	
	
	
	
	\$graph->SetShadow();";
	fwrite($Handle, $Data);	
	
	
	
	
	if($key==1){
	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
  
  //fwrite($Handle, $Data);
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  //$Data="
	
	$Data="
	
	

    \$graph->xaxis->SetTickLabels(\$datax);
    \$graph->xaxis->SetLabelAngle(90);

    \$graph->img->SetMargin(40,30,20,120);
    \$lineplot = new LinePlot(\$datay);
	\$lineplot2 = new LinePlot(\$datay2);
	

    ";
    
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot->mark->SetType(MARK_UTRIANGLE);
      \$lineplot->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
    
    //\$lineplot->value->Show();
	
	";
  
  fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot2->mark->SetType(MARK_UTRIANGLE);
      \$lineplot2->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
   // \$lineplot2->value->Show();
	
	
	
	
    \$graph->Add(\$lineplot);
	\$graph->Add(\$lineplot2);
	
    \$graph->title->Set(\"Rate of Diversity & Origination\");
    \$graph->xaxis->title->Set(\"Absolute Time Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Rate of Genera\");
    \$lineplot->SetColor(\"blue\");
    \$lineplot->SetWeight(2);
    \$lineplot->value->SetColor(\"blue\");
	
	\$lineplot2->SetColor(\"green\");
    \$lineplot2->SetWeight(2);
    \$lineplot2->value->SetColor(\"green\");
	
		
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
    fwrite($Handle, $Data);
    fclose($Handle);
    //$myFile = "../../../admin1/list/graph/jpgraph_cache/comb_dox.png";


    $myFile = "../../../graph/jpgraph_cache/comb_dox.png";
	if(file_exists($myFile)){
    unlink($myFile);
	}

    }



    else if($radio=="Rate3" && $d=="on" && $e=="on"){


    //$File = "../../../admin1/list/graph/comb_dox.php";

    $File = "../../../graph/comb_dox.php";
    $Handle = fopen($File, 'w');
    $Data = "<?php
      include (\"./src/jpgraph.php\");
      include (\"./src/jpgraph_line.php\");
	  \$datay=array$rated;
	  
	  \$datay3=array$ratee;

    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");
	
	
	
	\$graph->SetShadow();";
	fwrite($Handle, $Data);
	
	
	
	if($key==1){
	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
	
 // fwrite($Handle, $Data);
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  //$Data="
  
  $Data="
	
	
	

    \$graph->xaxis->SetTickLabels(\$datax);
    \$graph->xaxis->SetLabelAngle(90);

    \$graph->img->SetMargin(40,30,20,120);
    \$lineplot = new LinePlot(\$datay);
	
	\$lineplot3 = new LinePlot(\$datay3);

    ";
    
    
    fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot->mark->SetType(MARK_UTRIANGLE);
      \$lineplot->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
    //\$lineplot->value->Show();
	
	
	
	";
  
  fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot3->mark->SetType(MARK_UTRIANGLE);
      \$lineplot3->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
   // \$lineplot3->value->Show();
	
	
    \$graph->Add(\$lineplot);
	
	\$graph->Add(\$lineplot3);
    \$graph->title->Set(\"Rate of Diversity & Extinction\");
    \$graph->xaxis->title->Set(\"Absolute Time Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Rate of Genera\");
    \$lineplot->SetColor(\"blue\");
    \$lineplot->SetWeight(2);
    \$lineplot->value->SetColor(\"blue\");
	
	
	
	\$lineplot3->SetColor(\"orange\");
    \$lineplot3->SetWeight(2);
    \$lineplot3->value->SetColor(\"orange\");
	
	
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
    fwrite($Handle, $Data);
    fclose($Handle);
    //$myFile = "../../../admin1/list/graph/jpgraph_cache/comb_dox.png";

    $myFile = "../../../graph/jpgraph_cache/comb_dox.png";
	if(file_exists($myFile)){
    unlink($myFile);
	}

    }


    else if($radio=="Rate3" && $o=="on" && $e=="on"){
    //$File = "../../../admin1/list/graph/comb_dox.php";

    $File = "../../../graph/comb_dox.php";
    $Handle = fopen($File, 'w');
    $Data = "<?php
      include (\"./src/jpgraph.php\");
      include (\"./src/jpgraph_line.php\");
	  
	  \$datay2=array$rateo;
	  \$datay3=array$ratee;

    \$graph = new Graph(800,450,\"auto\");    
    \$graph->SetScale(\"textlin\");
	
	
	
	\$graph->SetShadow();";
	fwrite($Handle, $Data);	
	
	
	
	if($key==1){
	
		$Data="
			\$datax=array
			";
		fwrite($Handle, $Data);
		//$points="(\"$from\"";
		$range=$absolute*$xaxis_num+$end;
		//for($i=2;$i<= $xaxis_num;$i++){
			
			//$points=$points.","."\"".($range-$absolute*$i)."\"";
		//}
		
		
		$points="(\"$from"." - ".($range-$absolute)."\"";//ff
		for($i=1;$i<= $xaxis_num;$i++){//ff
			
			$points=$points.","."\"".($range-$absolute*$i)." - ".($range-$absolute*($i+1))."\"";//ff
			//echo "it is ".($range-$absolute*$i)."<br>";
		}
		
		$points=$points.")";
		$Data="$points;";
		fwrite($Handle, $Data);
	}
	
	
 // fwrite($Handle, $Data);
  if($xaxis_num>50&&$xaxis_num<=100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(2);
      ";
      fwrite($Handle, $Data);
  }
  if($xaxis_num>100){
    $Data="
      \$graph->xaxis->SetTextTickInterval(3);
      ";
      fwrite($Handle, $Data);
  }
  //$Data="
  
  $Data="
	
	

    \$graph->xaxis->SetTickLabels(\$datax);
    \$graph->xaxis->SetLabelAngle(90);

    \$graph->img->SetMargin(40,30,20,120);
    
	\$lineplot2 = new LinePlot(\$datay2);
	\$lineplot3 = new LinePlot(\$datay3);

    
	
	";
  
  fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot2->mark->SetType(MARK_UTRIANGLE);
      \$lineplot2->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
    //\$lineplot2->value->Show();
	
	";
  
  fwrite($Handle, $Data);
    if($label=="labelon" || $label==""){
      $Data="
      \$lineplot3->mark->SetType(MARK_UTRIANGLE);
      \$lineplot3->value->Show();
      ";
      fwrite($Handle, $Data);
     }
     $Data="
    //\$lineplot3->value->Show();
	
	
    
	\$graph->Add(\$lineplot2);
	\$graph->Add(\$lineplot3);
    \$graph->title->Set(\"Rate of Origination & Extinction\");
    \$graph->xaxis->title->Set(\"Absolute Time Interval\");
    \$graph->xaxis->title->SetMargin(80);
    \$graph->yaxis->title->Set(\"Rate of Genera\");
    
	
	\$lineplot2->SetColor(\"green\");
    \$lineplot2->SetWeight(2);
    \$lineplot2->value->SetColor(\"green\");
	
	\$lineplot3->SetColor(\"orange\");
    \$lineplot3->SetWeight(2);
    \$lineplot3->value->SetColor(\"orange\");
	
	
    \$graph->title->SetFont(FF_FONT1,FS_BOLD,8);
    \$graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD);
    \$graph->Stroke();
    ?>";
    fwrite($Handle, $Data);
    fclose($Handle);
    //$myFile = "../../../admin1/list/graph/jpgraph_cache/comb_dox.png";

    $myFile = "../../../graph/jpgraph_cache/comb_dox.png";
	if(file_exists($myFile)){
    unlink($myFile);
	}

    }



    $k=0;
    if($radio_o=='Rate2') {$k=$k+1;}
    if($radio_e=='Rate3') {$k=$k+1;}
    if($radio_d=='rate') {$k=$k+1;}
    //echo "k is $k<br>";
  
  if(($relative=="none" && $key==0)||(($e=="on"||$o=="on"||$d=="on")&&($radio=="Rate3")&& ($key==0))){
		  echo "<br><br>Invalid time option, please check your time selection/input and try again.";
		  }
		  //else if ($radio=="Rate3" && $key==0){
    	//echo "Please provide an interger between [5,50] in the text area of absolute time.22";

 // }
  else{ 
  //echo "<br><a href=\"http://www.fossilplot.org/test/new/v9/graph/fossilplot.csv\"><font color='red' size=1>Download CSV File of Data</font></a> ";

  if($d== "on"){
    if($o=="on"){
      if($e=="on"){
        echo "<div class=\"tabber\" id=\"tab1\">";          

          echo "<div class=\"tabbertab\" title=\"Diversity\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writedvt.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";
		  //echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";
          echo "</div>";
          
          echo "<div class=\"tabbertab\" title=\"Origination\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">"; 
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/write.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";
		  
		  //echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">";
          echo "</div>";


          echo "<div class=\"tabbertab\" title=\"Extinction\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writeext.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";
		  
		  //echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";
          echo "</div>";
		  if($radio=="Rate3"){
			
				echo "<div class=\"tabbertab\" title=\"Rate_DOX\">";
				echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/comb_dox.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";
				
				//echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";
				echo "</div>";
					  
		  }
        echo "</div>";
      
      }
      else { // e is not on, o and d are on    
        echo "<div class=\"tabber\" id=\"tab1\">";          

          echo "<div class=\"tabbertab\" title=\"Diversity\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";

		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writedvt.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

		  //echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";
          echo "</div>";
          
          echo "<div class=\"tabbertab\" title=\"Origination\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">"; 

		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/write.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

		  //echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">"; 
          echo "</div>";
		  
		  if($radio=="Rate3"){
			echo "<div class=\"tabbertab\" title=\"Rate_D.O.\">";
			echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";

		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/comb_dox.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

			//echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";
			echo "</div>";
		  
		  }
		  
        echo "</div>";      
      }    
    }
    else{ //o is not on, d is on, e is on or not
      if($e=="on"){ //d is on and e is on, o not on
        echo "<div class=\"tabber\" id=\"tab1\">";          

          echo "<div class=\"tabbertab\" title=\"Diversity\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";

		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writedvt.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

		  //echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";
          echo "</div>";
          
          echo "<div class=\"tabbertab\" title=\"Extinction\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";

		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writeext.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

		  //echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";
          echo "</div>";
		  
		  if($radio=="Rate3"){
			echo "<div class=\"tabbertab\" title=\"Rate_D.X.\">";
			echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";

		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/comb_dox.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

			//echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";
			echo "</div>";
		  
		  }
		  
		  
        echo "</div>";     
      
      }
      else{ //e and o are not on
        echo "<div class=\"tabber\" id=\"tab1\">";          

          echo "<div class=\"tabbertab\" title=\"Diversity\">";
          echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";

		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writedvt.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

		  //echo "<img src=\"http://www.fossilplot.org/test/graph/writedvt.php\">";
          echo "</div>";          
          
        echo "</div>";      
      
      }    
    }// for 'else{ //o is not on, d is on, e is on or not'
  
  }
  else{ //$d is not on
    if($o=="on"){
      if($e=="on"){
          echo "<div class=\"tabber\" id=\"tab1\">";  
            echo "<div class=\"tabbertab\" title=\"Origination\">";
            echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">";
			
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/write.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

			
			//echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">";
            echo "</div>";  
            echo "<div class=\"tabbertab\" title=\"Extinction\">";
            echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";
			
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writeext.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

			
			//echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";
            echo "</div>";
			
			if($radio=="Rate3"){
			echo "<div class=\"tabbertab\" title=\"Rate_O.X.\">";
			echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";
			
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/comb_dox.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

			
			//echo "<img src=\"http://www.fossilplot.org/test/graph/comb_dox.php\">";
			echo "</div>";
		  
		  }
			
			
			
          echo "</div>";
      
      }else{ //only o is on
          echo "<div class=\"tabber\" id=\"tab1\">";  
            echo "<div class=\"tabbertab\" title=\"Origination\">";
            echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">";
			
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/write.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

			
			//echo "<img src=\"http://www.fossilplot.org/test/graph/write.php\">"; 
            echo "</div>";            
          echo "</div>";
      
      }    
    
    }
    else { // d and o are off
      if ($e =="on"){
        echo "<div class=\"tabber\" id=\"tab1\">";  
            echo "<div class=\"tabbertab\" title=\"Extinction\">";
            echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";
			
		  echo "<br><br></br><a href=\"http://www.fossilplot.org/test/graph/jpgraph_cache/writeext.png\" target=\"_blank\"><font size=\"1\"> Download/Print Graph</font></a>";

			
			//echo "<img src=\"http://www.fossilplot.org/test/graph/writeext.php\">";
            echo "</div>";
          echo "</div>";
      
      }
      else{ //d,o,x are off
        echo "<br><br>please select Diversity, Origination, or Extinction for the graph.";
      
      }
    
    
    }
  
  
  }
 }
  
  
  
?>

<?php include 'footer.php';?>
 </body>

</html>